/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package semant.first_pass;

import errors.ErrorEchoer;
import semant.Env;
import symbol.ClassInfo;
import symbol.MethodInfo;
import symbol.Symbol;
import symbol.VarInfo;
import syntaxtree.IntArrayType;
import syntaxtree.IntegerType;
import syntaxtree.MainClass;
import syntaxtree.Program;
import syntaxtree.VisitorAdapter;

/**
 *
 * @author Thiago
 */
class MainClassHandler extends VisitorAdapter {

    private Env env;

    private MainClassHandler(Env e)
    {
        super();

        env = e;
    }

     static void firstPass(Env e, MainClass m)
    {
        MainClassHandler h = new MainClassHandler(e);

        m.accept(h);
    }

    public void visit(MainClass node)
    {
        Symbol name = Symbol.symbol(node.className.s);

        ClassInfo info = new ClassInfo(name);

        MethodInfo m = new MethodInfo(new IntegerType(node.line,node.row),Symbol.symbol("main"),null);

        info.methods.put(Symbol.symbol("main"), m);

        IntArrayType t = new IntArrayType(node.line,node.row);

        VarInfo var = new VarInfo(t,Symbol.symbol(node.mainArgName.s));

        

        if(!env.classes.put(name,info))
        {
            env.err.Error(node,new Object[]{"Nome de classe redefinido.","Simbolo: "+node.className});
        }
        
        
    }

}
